import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        userInfo: JSON.parse(localStorage.getItem('user')) ,
        islogin: false,
        circleUrl: ''
    },
    mutations: {
        setUserInfo(state,value) {
            localStorage.setItem('user',value)
            state.userInfo = JSON.parse(value)
        },
        setUserHead(state,value){
            state.circleUrl = value
        }
    },
    actions: {
        getuserinfo(state) {
            this.state.userInfo=JSON.parse(localStorage.getItem('user'))
            if (this.state.userInfo == null) {
                this.state.islogin = false;
            } else {
                this.state.islogin = true
                if (this.state.userInfo.userHead) {
                    this.state.circleUrl = this.state.userInfo.userHead
                } else this.state.circleUrl = "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
            }
        }
    },
    modules: {
    }
})